﻿Public Class UCBaoCao
    Sub ddlLoaiNhaLoad()
        Dim sql As String = "select * from LoaiNha"
        ddlLoaiNha.DataSource = DataProvider.LoadTable(sql)
        ddlLoaiNha.DisplayMember = "TENLOAINHA"
        ddlLoaiNha.ValueMember = "MALOAINHA"
        ddlLoaiNha.SelectedIndex = 0
    End Sub

    Sub GridView_Load()
        'GControl.DataSource = 
    End Sub
    Function TestInfo() As Boolean
        If txtNBD.Text = "" Or txtNKT.Text = "" Then
            ThongBao.TestInfo()
            Return False
        End If
        Return True
    End Function

    Private Sub UCBaoCao_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ddlLoaiNhaLoad()
        txtNKT.Text = DateTime.Now.ToShortDateString
        txtNBD.Text = DateTime.Now.AddDays(-30).ToShortDateString
    End Sub
    Function BCLoaiNhaTheoThangLoad() As DataTable
        Dim manha As Integer = ddlLoaiNha.SelectedValue
        Dim sql As String = String.Format("exec usp_BaoCaoLoaiNhaTheoThang {0}, '{1}', '{2}'", manha, txtNBD.Text, txtNKT.Text)
        Return(DataProvider.LoadTable(sql))
    End Function
    Private Sub btnBaoCaoLoaiNha_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaoCaoLoaiNha.Click
        GControl.DataSource = BCLoaiNhaTheoThangLoad
    End Sub
    Function BCThangLoad() As DataTable
        Dim sql As String = String.Format("exec usp_BaoCaoTheoThang '{0}', '{1}'", txtNBD.Text, txtNKT.Text)
        Return (DataProvider.LoadTable(sql))
    End Function
    Private Sub btnBaoCaoThang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaoCaoThang.Click
        If Not TestInfo() Then
            Return
        End If
        GControl.DataSource = BCThangLoad
    End Sub

    Private Sub btnXuatBaoCao_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnXuatBaoCao.Click
        GControl.ShowPrintPreview
    End Sub
    Public Function DataSource() As DataTable
        Return GControl.DataSource
    End Function

    Private Sub SimpleButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim r As New rptBaoCao
        r.DataSource = DataProvider.LoadTable("select * from HOADON")
        'r.DataSource = r.getData
        r.LayDuLieuVaoCot()
        r.ShowDesigner()
    End Sub
End Class
